﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Contact.DAL.Models.Worktime;
using ContactMvc4TB.Models.Worktime.Helpers;
using EFDataModel;

namespace ContactMvc4TB.Models.Worktime
{
    /// <summary>
    /// Model zum Anzeigen der Projektlisteneinträge für die Arbeitszeitverwaltung.
    /// </summary>
    public class WorktimeProjectListModel
    {
        #region ModelData
        /// <summary>
        /// Die aktuelle UserId für die die Projekteinträge
        /// </summary>
        public long UserId { get; set; }

        /// <summary>
        /// Die Liste mit den Urlaubszeiten.
        /// </summary>
        public List<ProjectEntry> ProjectEntries { get; set; }
        #endregion

        #region Public Functions
        /// <summary>
        /// Laden der Modeldaten.
        /// </summary>
        /// <param name="userId">Die UserId für die die Modeldaten geladen werden sollen.</param>
        /// <returns>TRUE->Listendaten vorhanden | FALSE->Noch keine Listendatenvorhanden</returns>
        public bool LoadModelData(long userId)
        {
            UserId = userId;
            ProjectEntries = new List<ProjectEntry>();

            //Laden der Projekteinträge aus der DB.
            WorktimeSettingsRepository worktimeSettings = new WorktimeSettingsRepository(CurrentHttpContext.GetDataModel());
            foreach (EFWorktimeProject project in worktimeSettings.LoadProjects(UserId))
            {
                ProjectEntries.Add(new ProjectEntry() { Id = project.Id, Name = project.Name, Description = project.Description, ShowEntry = project.ShowEntry, Sortorder = project.Sortorder });
            }

            if (ProjectEntries.Count > 0)
            {
                return true;
            }

            return false;
        }
        #endregion
    }
}